/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edu.kamai.xmlparser;

import java.io.FileWriter;
import java.io.IOException;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

/**
 *
 * @author xyzhu
 */
public class JDomCreatingXml {
    
    //
    // <rows>
    //     <row>
    //         <firstname>Alice</firstname>
    //         <lastname>Starbuzz</lastname>
    //         <address>Sunset Read</address>
    //     </row>
    // </rows>
    //
    
    
    public static void main(String[] args) {
        Document document = new Document();
        Element root = new Element("rows");

        Element child = new Element("row");
        child.addContent(new Element("firstname").setText("Alice"));
        child.addContent(new Element("lastname").setText("Starbuzz"));
        child.addContent(new Element("address").setText("Sunset Road"));
        root.addContent(child);
        document.setContent(root);
        try {
            FileWriter writer = new FileWriter("userinfo.xml");   
            XMLOutputter outputter = new XMLOutputter();
            
            outputter.setFormat(Format.getPrettyFormat());
            outputter.output(document, writer);

            outputter.output(document, System.out);
            
            
            
        }catch (IOException e) {
            e.printStackTrace();
        }

        
    }
}
